<!doctype html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="resources/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/signin.css">
    <script src="resources/angular/angular.min.js"></script>
    <title>Document</title>
</head>
<body ng-controller="appCtrl">
<div class="signin">
    <div class="signin-head text-center" style="height: 150px;width: inherit;">
        <h1><b>用户登录</b></h1>
    </div>
    <form class="form-signin" role="form">
        <input type="text" class="form-control" placeholder="用户名" required autofocus ng-model="user.username"/>
        <input type="password" class="form-control" placeholder="密码" required ng-model="user.password"/>
        <button class="btn btn-lg btn-warning btn-block" ng-click="submit()">登录</button>
    </form>
</div>
<script>
    var app = angular.module('app', []);
    app.controller('appCtrl', ['$scope', '$http', function ($scope, $http) {
        $scope.getContextPath = function () {
            var pathName = document.location.pathname;
            var index = pathName.substr(1).indexOf("/");
            var result = pathName.substr(0, index + 1);
            return result;
        }
        var ctx = window.location.origin + $scope.getContextPath();
        $scope.user = {
            username: '',
            password: ''
        };
        $scope.submit = function () {
            $http.post(ctx + '/login', $scope.user).then(function (resp) {
                if (resp.data) {
                    window.location.href = ctx + '/';
                } else {
                    alert('用户名或密码错误');
                }
            });
        }
    }]);
</script>
</body>
</html>